package com.zjj.lbw.microservice.sentinel.app.demo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zjj.lbw.common.bean.R;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhanglei.zjj
 * @description Sentinel 热点参数规则
 * @date 2023/7/29 17:01
 */
@RestController
public class HotParamRuleTest {
    @RequestMapping("/info/{id}")
    @SentinelResource(value = "userinfo", blockHandler = "handleException")
    public R info(@PathVariable("id") Integer id) {
        return R.ok().put("userName", "zjj-" + id);
    }

    public R handleException(Integer id, BlockException ex) {
        return R.ok().put("userName", "===被限流降级啦===");
    }
}
